package com.global.base;

import org.hibernate.SessionFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;

/**
 * Base class for running DAO tests. 
 * @author zly601436
 *
 */
public abstract class BaseDaoTestCase extends BaseTestCase {
	
    @Autowired
    private SessionFactory sessionFactory;

    /**
     * Create a HibernateTemplate from the SessionFactory and call flush() and clear() on it.
     * Designed to be used after "save" methods in tests: http://issues.appfuse.org/browse/APF-178.
     *
     * @throws org.springframework.beans.BeansException when can't find 'sessionFactory' bean
     */
    protected void flush() throws BeansException {
    	
        HibernateTemplate hibernateTemplate = new HibernateTemplate(sessionFactory);

        hibernateTemplate.flush();
        hibernateTemplate.clear();
    }
}
